﻿using FastExecutor.Base.Design;
using FastExecutor.ORG.Entity;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace FastExecutor.ORG.Controller
{
    [RouteArea("Frame")]
    [RoutePrefix("ErrorLog")]
    public class ErrorLogController : FastTemplateController<Frame_ErrorLog>
    {
        [Route("List")]
        public ActionResult List()
        {
            return View("~/Views/Frame/Log/ErrorLog_List.cshtml");
        }

        [Route("Detail")]
        public ActionResult Detail()
        {
            return View("~/Views/Frame/Log/ErrorLog_Detail.cshtml");
        }

        [HttpPost, Route("FindList")]
        public override ActionResult FindList()
        {
            JObject Params = GetParams();
            string ErrorType = Convert.ToString(Params["ErrorType"]);
            string StartDate = Convert.ToString(Params["StartDate"]);
            string EndDate = Convert.ToString(Params["EndDate"]);
            if (!string.IsNullOrEmpty(ErrorType))
            {
                ListWhereText += string.Format(" and ErrorType={0}", Convert.ToInt32(ErrorType));
            }
            if (!string.IsNullOrEmpty(StartDate))
            {
                ListWhereText += string.Format(" and ErrorDate>=DATE_FORMAT('{0}','%Y-%m-%d')", Convert.ToDateTime(StartDate).ToString("yyyy-MM-dd"));
            }
            if (!string.IsNullOrEmpty(EndDate))
            {
                ListWhereText += string.Format(" and ErrorDate<=DATE_FORMAT('{0}','%Y-%m-%d')", Convert.ToDateTime(EndDate).ToString("yyyy-MM-dd"));
            }
            OrderText = "ErrorDate desc";
            return base.FindList();
        }

        [HttpPost, Route("FindDetail")]
        public override ActionResult FindDetail()
        {
            return base.FindDetail();
        }
    }
}
